<template>
	<view class="container" v-if="isWechat()">
		<image class="bg" :src="$setting.imageUrl()+'zhaoshangtupian.jpg'" mode="widthFix"></image>

		<view :style="{height: placeholderHeight}"></view>
		
		<view class="fixed-bottom">
			<view class="flex-align-center" style="justify-content: space-around;">
				<b-u-button-theme height="90rpx" width="300rpx" @click="jump('/pages/index/form')">诚邀合作</b-u-button-theme>
				
				<b-u-button-theme height="90rpx" width="300rpx" @click="makePhone">
					<view class="contact flex-column-center">
						<view class="" style="height: 40rpx;">400-1808-119</view>
						<view class="flex-align-center">
							<image class="contact-image" :src="$setting.imageUrl()+'contact2.png'"></image>
							<view class="">联系我们</view>
						</view>
					</view>
				</b-u-button-theme>
			</view>
			
			<view class="safe-area-inset-bottom"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				placeholderHeight: "",
				type:'mp'
			}
		},
		onLoad() {
			
			var params = this.getParamsFromURL();
			this.type = params.type
			this.$nextTick(() => {
				const query = uni.createSelectorQuery();
				query.in(this).select('.fixed-bottom').boundingClientRect();
				query.exec((res) => {
					this.placeholderHeight = res[0].height + 'px';
				})
			})
			if (!this.isWechat()) {
				uni.showModal({
					title: '提示',
					content: '请在微信上打开此网页',
					showCancel: false,
				});
			}
		},
		methods: {
			getParamsFromURL() {
			  var url = window.location.search;
			  var result = {};
			  var reg = /[?&]([^=&#]+)=([^&#]*)/g;
			  
			  url.replace(reg, function(match, key, value) {
			    result[decodeURIComponent(key)] = decodeURIComponent(value);
			  });
			  
			  return result;
			},
		
			makePhone() {
				if(this.type == 'h5'){
					var phoneNumber = 4001808119;
					var callLink = 'tel:' + phoneNumber;
					var link = document.createElement('a');
					link.setAttribute('href', callLink);
					link.setAttribute('style', 'visibility:hidden');
					document.body.appendChild(link);
					link.click();
				}else{
					uni.makePhoneCall({
						phoneNumber: '4001808119'
					});
				}
				
			},
			isWechat() {
			
				if(this.type == 'h5'){
					return true;
				}else{
					var ua = navigator.userAgent.toLowerCase()
					var isWXWork = ua.match(/wxwork/i) == 'wxwork'
					var isWeixin = !isWXWork && ua.match(/MicroMessenger/i) == 'micromessenger'
					return isWeixin;
				}
				
				
			},
			jump(url) {
				uni.navigateTo({
					url: url
				})
			},
			getHttp() {

			},
		},
	}
</script>

<style lang="scss" scoped>
	.container {
		
		.bg {
			width: 100%;
		}
		
		.fixed-bottom {
			position: fixed;
			bottom: 0;
			left: 0;
			z-index: 99;
			width: 100%;
			padding: 20rpx 30rpx;
			
			.contact {
				
				.contact-image {
					width: 35rpx;
					height: 35rpx;
					margin-right: 10rpx;
				}
			}
		}
	}
</style>